//
//  STSellerDetailViewController.m
//  赛拓
//
//  Created by 王磊 on 8/9/16.
//  Copyright © 2016 立金所. All rights reserved.
//

#import "STSellerDetailViewController.h"
#import "STTitleView.h"
#import "STCommodityListViewController.h"
#import "STBuyersViewController.h"
#import "STCommodityDetailViewController.h"
@interface STSellerDetailViewController ()<STBaseViewDelegate>
@property (nonatomic ,strong) NSArray *viewControllers;

@property (nonatomic ,strong) UIPageViewController *page;

@property (nonatomic ,assign) NSInteger selectedIndex;
@end

@implementation STSellerDetailViewController

- (void)initSubviews {
    [super initSubviews];
    
    
    [self initTitleView];
    
    [self initPageVc];
}
- (void)initTitleView {
    STTitleView *titleView = [STTitleView instance];
    
    titleView.titles = @[@"产品列表",@"商家信息"];
    
    titleView.font = ST_15_FONT;
    
    titleView.mDelegate = self;
    
    [self.view addSubview:titleView];
    
    titleView.frame = CGRectMake(0, 0, ST_SCREEN_WIDTH, 30);
}
- (void)initPageVc {
    
    self.selectedIndex = 0;
    
    STCommodityListViewController *commodity = [STCommodityListViewController instance];
    @WeakObj(self)
    commodity.block =  ^(id itemClickType ,id mDate ,id indexPath) {
        STItemClickType itemType = [itemClickType integerValue];
        
        [selfWeak onItemClick:itemType withData:mDate forIndexPath:indexPath];
        
    };
    
    STBuyersViewController *buyers = [STBuyersViewController instance];
    
    //    buyers.block =  ^(id itemClickType ,id mDate ,id indexPath) {
    //        STItemClickType itemType = [itemClickType integerValue];
    //
    //        [selfWeak onItemClick:itemType withData:mDate forIndexPath:indexPath];
    //
    //    };
    
    self.viewControllers = @[commodity ,buyers];
    
    UIPageViewController *pageVC = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:@{UIPageViewControllerOptionSpineLocationKey: @(UIPageViewControllerSpineLocationMin)}];
    
    self.page = pageVC;
    
    pageVC.view.frame = CGRectMake(0, 30 , ST_SCREEN_WIDTH, CGRectGetHeight(self.view.bounds) - 30);
    
    [pageVC setViewControllers:@[self.viewControllers[self.selectedIndex]] direction:UIPageViewControllerNavigationDirectionForward animated:true completion:nil];
    
    [self.view addSubview:pageVC.view];
    
}

- (void)loadData {
    
    self.loadingView.loadingStatus = BDLoadingStatusSuccess;
    
    
}
- (void)onItemClick:(STItemClickType)itemType withData:(id)data forIndexPath:(NSIndexPath *)indexPath {
    
    switch (itemType) {
        case STItemClickTypeTitle:
        {
            
            UIPageViewControllerNavigationDirection direction = indexPath.row > self.selectedIndex ? UIPageViewControllerNavigationDirectionForward : UIPageViewControllerNavigationDirectionReverse;
            
            UIViewController *vc = self.viewControllers[indexPath.row];
            
            [self.page setViewControllers:@[vc] direction:direction animated:true completion:nil];
            
            self.selectedIndex = indexPath.row;
            
            
        }
            break;
        case STItemClickTypeItem: {
            STCommodityDetailViewController *goods = [STCommodityDetailViewController instance];
            
            [self.navigationController pushViewController:goods animated:true];
            
            
        }
            break;
        default:
            break;
    }
    
    
}
@end
